<template>
  <el-container>
    <!-- aside -->
    <el-aside width="200">
      <h1 class="logo"></h1>
      <el-menu
        :default-active="$route.path"
        :collapse="collapse"
        class="ql-menu"
      >
        <qf-sub-menu :sideMenu="sideMenu"></qf-sub-menu>
      </el-menu>
    </el-aside>
    <el-container>
      <!-- header -->
      <el-header>
        <el-row type="flex" class="row-bg" justify="space-around">
          <el-col :span="6"
            ><div class="grid-content left">
              <i
                :class="['iconfont', collapse ? 'icon-zhankai' : 'icon-shouqi']"
                @click="collapse = !collapse"
              ></i></div
          ></el-col>
          <el-col :span="6"
            ><div class="grid-content center">CRM管理系统</div></el-col
          >
          <el-col :span="6">
            <div class="grid-content right">
              <el-avatar
                shape="square"
                size="large"
                :src="avaterUrl"
              ></el-avatar>
              <b
                >欢迎你<el-dropdown @command="handleCommand">
                  <span class="el-dropdown-link">
                    下拉菜单<i class="el-icon-arrow-down el-icon--right"></i>
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item divided
											command="charge"
											v-if="userInfo.vipLevel"
											>vip到期时间:<br /></el-dropdown-item>
										<el-dropdown-item divided
											command="charge"
											>vip充值</el-dropdown-item>
										<el-dropdown-item divided
											command="mine"
											>账号信息</el-dropdown-item>
										<el-dropdown-item divided
											command="product"
											>项目管理</el-dropdown-item>
										<el-dropdown-item divided
											@click.native="quit">退出</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown></b
              >
              &nbsp;
              <b class="quit" @click="quit">退出登录</b>
              <!-- <button @click="fasong">发送</button> -->
            </div>
          </el-col>
        </el-row>
      </el-header>
      <!-- main -->
      <el-main>
        <!-- 我们把面包屑放在这里 -->
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item
            :to="{ path: item.path }"
            v-for="item in breadCrumb"
            :key="item.name"
          >
            {{ item.meta.name }}
          </el-breadcrumb-item>
        </el-breadcrumb>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { mapState } from "vuex";
export default {
  computed: {
    ...mapState(["userInfo", "sideMenu", "breadCrumb"]),
    avaterUrl() {
      return this.userInfo.headimgurl
        ? this.userInfo.headimgurl
        : "https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png";
    },
  },
  mounted() {
    // console.log(this.userInfo);
  },
  methods: {
    handleCommand(routerName) { // 下拉菜单
     //routerName就是下拉菜单传入的路由名字
				if (routerName) {
					this.$router.push({ name: routerName });
				}
    },
    // fasong() {
    //   // console.log("111");
    //   this.$store.dispatch('GET_MENULIST')
    // },
    quit() {
      // 点击退出 1.清除token
      localStorage.removeItem("qf-token");
      // 2.跳转到登入页
      this.$router.push("/login");
      // 3.页面刷新
      location.reload();
    },
  },
  data() {
    return {
      collapse: false,
    };
  },
};
</script>

<style lang="less">
.el-header {
  background: linear-gradient(135deg, #4c67ff, #5635df);
  color: #fff;
  text-align: center;
  min-height: 60px;
  padding: 0;
  //   line-height: 60px;
  line-height: 40px;
  .left {
    text-align: left;
    i {
      font-size: 30px;
    }
  }
  .center {
    font-size: 30px;
  }
  .right {
    b {
      margin-left: 5px;
    }
  }
  .el-avatar {
    vertical-align: middle;
  }
  .quit {
    color: hotpink;
    cursor: pointer;
  }
}
  
.el-aside {
  background: linear-gradient(135deg, #4c67ff, #5635df);
  color: #fff;
  text-align: center;
  line-height: 200px;
  .logo {
    min-height: 60px;
    // background: #fff;
  }
  .subMenu {
    text-align: left;
  }
  .ql-menu:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
}
.el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }

.el-main {
  background-color: #e9eef3;
  color: #fff;
  text-align: center;
  //   line-height: 160px;
}

.el-container {
  margin-bottom: 40px;
  height: 100%;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
}
</style>